home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-25 | 9.3 KB | 217 lines | [TEXT/MACA] |
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;
- ; File: SM-TEST.LISP
- ; Author: Dan Suthers
- ; Created: 04-Jun-88 13:33:02
- ; Modified: 22-Jun-90 02:13:54 (Dan Suthers)
- ; Language: LISP
- ; Package: USER
- ;
- ; Description: For testing SM.LISP when it is changed. One should load
- ; this file after loading SM and check the printed results.
- ; Do it for both uncompiled and compiled versions of this
- ; file, in SEPARATE lisp sessions.
- ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (in-package :user)
-
- (require :SM)
-
- (setf *print-pretty* t)
-
- (format T "~%~%---------- STRUCTURE TYPE DEFINITION TESTS ----------")
- (format T "~%Creating a test structure with:
- (sm:dst (test (:comments \"A structure to test SM with.\"))
- (weight 0.0 :type float :computed nil :read-only t
- :comments \"The value of this slot will be computed.\")
- (computed-weight 0.0
- :type float
- :computed t
- :if-needed (lambda (i) (* 0.5 (test-weight (sm:gets 'test i))))
- :compiled-if-needed nil)
- (nested-list nil :type list
- :comments \"This slot is to show how the print options work.\")
- (comments \"\" :type string))")
- (sm:dst (test (:comments "A structure to test SM with."))
- (weight 0.0 :type float :computed nil :read-only t
- :comments "The value of this slot will be computed.")
- (computed-weight 0.0
- :type float
- :computed t
- :if-needed (lambda (i) (* 0.5 (test-weight (sm:gets 'test i))))
- :compiled-if-needed nil)
- (nested-list nil :type list
- :comments "This slot is to show how the print options work.")
- (comments "" :type string))
-
- (format T "~%COMPUTED-SLOTS is (COMPUTED-WEIGHT):")
- (format T " ~S" (sm:computed-slots 'test))
- (format T "~%UNCOMPUTED-SLOTS is (WEIGHT NESTED-LIST COMMENTS):")
- (format T " ~S" (sm:uncomputed-slots 'test))
- (format T "~%READ-ONLY-SLOTS is (WEIGHT):")
- (format T " ~S" (sm:read-only-slots 'test))
- (format T "~%CREATOR is CREATE-TEST:")
- (format T " ~S" (sm:creator 'test))
- (format T "~%DEFINING-FORM:~%")
- (format T " ~S" (sm:defining-form 'test))
- (format T "~%TYPE-INFO:")
- (format T " ~S" (sm:type-info 'test))
- (format T "~%REUSABLE is NIL:")
- (format T " ~S" (sm:reusable 'test))
- (format T "~%SLOT-ACCESS is alist of names to access functions: ~%")
- (format T " ~S" (sm:slot-access 'test))
- (format T "~%SLOT-DEFAULTS is alist of names to default values: ~%")
- (format T " ~S" (sm:slot-defaults 'test))
- (format T "~%SLOT-INFO is alist of names to info: ~%")
- (format T " ~S" (sm:slot-info 'test))
- (format T "~%SLOT-TYPES is alist of names to allowed data types: ~%")
- (format T " ~S" (sm:slot-types 'test))
-
- (format T "~%Creating a test instance:")
- (format T " ~S"
- (test t1
- :weight 0.5
- :nested-list (foo '#(0 1 2 3 4 5 6 7 8 9)
- (A (LONG LIST) fum ((far) foe) fazz fee fie foe fum english man blood)
- ("A string in the list")
- (sm::symbols sm::in sm::sm-package)
- ((doo ((:these :are :keywords) dee)) dum) ha)
- :comments "An instance to test TEST."))
-
- (format T "~%Copying it to another instance:")
- (format T " ~S" (sm:copies 'test 't1 't2))
-
- (format T "~%~%---------- PRINTING TESTS ----------")
- (format t "~%Printing NAME: ")
- (sm:prints 'test 't1 :style :name)
- (format t "~%Printing BRIEF:~%")
- (sm:prints 'test 't1 :style :brief)
- (format t "~%Printing SUMMARY:~%")
- (sm:prints 'test 't1 :style :summary)
- (format t "~%Printing PRETTY:~%")
- (sm:prints 'test 't1 :style :pretty)
- (format T "~%Check that the copied instance is the same:~%")
- (sm:prints 'test 't2 :style :pretty)
- (format t "~%Printing MACRO:~%")
- (sm:prints 'test 't1 :style :macro)
- (format t "~%Printing PRETTY-MACRO:~%")
- (sm:prints 'test 't1 :style :pretty-macro)
-
-
- (format T "~%~%---------- SLOT INFO TESTS ----------")
- (format T "~%Compiling the :if-needed method of TEST and saving it in its INFO list:")
- (format T " ~S"
- (setf (sm:slot-info 'test 'computed-weight :compiled-if-needed)
- (compile nil (sm:slot-info 'test 'computed-weight :if-needed))))
-
- (format T "~%Using the :compiled-if-needed to compute the computed-weight (0.25):")
- (format T " ~S"
- (setf (test-computed-weight (sm:gets 'test 't1))
- (funcall (sm:slot-info 'test 'computed-weight :compiled-if-needed)
- 't1)))
-
- (format T "~%~%---------- FREELIST TESTS ----------")
- (format T "~%Creating a reusable structure type:")
- (sm:dst (reusable-structure (:reusable t)
- (:comments "We reuse the memory of this one."))
- slot1 slot2)
- (format t "~%Make instance R1 of REUSABLE-STRUCTURE:")
- (format T " ~S"
- (reusable-structure r1 :slot1 "hi" :slot2 "there"))
- (format t "~%Instances now (R1):")
- (format T " ~S" (sm:instances 'reusable-structure))
- (format t "~%Destroy it:")
- (format T " ~S" (sm:destroys 'reusable-structure 'r1))
- (format t "~%Freelist of REUSABLE-STRUCTURE has a structure on it:")
- (format T " ~S"
- (sm::structure-type-freelist (get 'reusable-structure 'sm::$structure-type$)))
- (format t "~%Make instance R2 of REUSABLE-STRUCTURE:")
- (format T " ~S"
- (reusable-structure r2 :slot1 "another" :slot2 "go round"))
- (format t "~%Instances now (R2):" )
- (format T " ~S" (sm:instances 'reusable-structure))
- (format t "~%Freelist of REUSABLE-STRUCTURE now NIL:")
- (format T " ~S"
- (sm::structure-type-freelist (get 'reusable-structure 'sm::$structure-type$)))
- (format T "~%Destroying al instances via RESET-TYPE:")
- (format T " ~S" (sm:reset-type 'reusable-structure))
- (format T "~%Flushing freelist of REUSABLE-STRUCTURE:")
- (format T " ~S" (sm:flush-freelist 'reusable-structure))
- (format t "~%Freelist of REUSABLE-STRUCTURE now NIL:")
- (format T " ~S"
- (sm::structure-type-freelist (get 'reusable-structure 'sm::$structure-type$)))
-
- (format T "~%~%---------- REDEFINING TESTS ----------")
- (setf sm:*warn-of-redefinitions* t)
- (format T "~%Redefining TEST with warnings on and:
- (sm:define-type '(test (:redefine t)
- (:comments \"A structure to test SM with.\"))
- '(weight 1.0 :type float :computed nil :read-only nil)
- '(computed-weight 0.0
- :type float
- :computed t
- :if-needed (lambda (i) (* 0.5 (test-weight (sm:gets 'test i))))
- :compiled-if-needed nil)
- '(nested-list '((())) :type list :computed t)
- '(comments \"New Test Comments\" :type string))")
- (sm:define-type '(test (:redefine t)
- (:comments "A structure to test SM with."))
- '(weight 1.0 :type float :computed nil :read-only nil)
- '(computed-weight 0.0
- :type float
- :computed t
- :if-needed (lambda (i) (* 0.5 (test-weight (sm:gets 'test i))))
- :compiled-if-needed nil)
- '(nested-list '((())) :type list :computed t)
- '(comments "New Test Comments" :type string))
- (format T "~%Compare this reincarnation of T2 to its previous form:~%")
- (sm:prints 'test 't2 :style :pretty)
-
- (format T "~%~%---------- FILE I/O TESTS ----------")
- (format T "~%Known types are (REUSABLE-TYPE TEST):")
- (format T " ~S" (sm:structure-types))
- (format T "~%Saving TEST type to a file, pretty-macro form with type definition:")
- (format T " ~S"
- (sm:save-type 'test
- :path "test.lisp"
- :style :pretty-macro
- :define-type t
- :compile t))
- (format T "~%Destroying all types:" )
- (format T " ~S" (sm:destroy-all-types))
- (format T "~%Known types are (NIL):")
- (format T " ~S" (sm:structure-types))
- (format T "~%Loading file we just saved:")
- (format T " ~S" (sm:load-type 'test :path "test.lisp"))
- (format T "~%Known types are (TEST):")
- (format T " ~S" (sm:structure-types))
-
- (format T "~%~%---------- EMBEDDED DEFINE-TYPE TEST ----------")
- (format T "~%First some background.
- If a DST is not at top level, then its PROGN expansion won't be either.
- On some machines, PROGN is treated differently when not at top
- level. For expample, the HP preprocessor tries to expand SETFs
- in the CREATE-<type> definition. For :reusable types, there are
- SETFs to slot access functions defined in the DEFSTRUCT. However,
- even though the DEFSTRUCT occurs before the CREATE-<type> in the
- PROGN, it has not been evaluated yet (at preprocessor time). The
- result is a 'no setf method known for <type>-<slot>' error. On
- such machines, DST can only occur at top level.
-
- In contrast, DEFINE-TYPE should be usable anywhere. The following
- is a test of a DEFINE-TYPE no at top level, to ensure this is true.~%")
-
- (format T "~%If this prints, it worked: you can put DEFINE-TYPE
- not at top level: ~S But compile it to be sure!"
- (sm:define-type '(not-top-level-test (:reusable t))
- '(slot1 nil :type list)
- '(slot2 0.0 :type float)))
-
- (format T "~%~%---------- END of TEST of SM----------
- Note: to be sure, try loading both lisp and compiled versions of this
- test, IN DIFFERENT LISP SESSIONS, so the second test does not rely on
- things defined in the first.~%")
-
- ;;; EOF
-